<?php
if(isset($_SESSION['login']['ID']))
{
	
	$query = "SELECT * FROM Webshops WHERE CustomerID = '".str_replace("'","",$_SESSION['login']['ID'])."' ORDER BY Name ASC";
	$result = $_MySQL->runQuery($query);
	?>
	<table width="100%" border="0">
		<tr>
			<td width="4%" height="36">&nbsp;</td>
			<td width="28%">
				<input type="button" onClick="javascript: openPopup('/popup/newwebshop.php', 'Nieuwe Webshop toevoegen', 900, 500);" value=" Webshop Toevoegen " />
				<!-- 
				<input type="submit" name="button2" id="button2" value="Verwijder Selectie" />
				-->
			</td>
			<td colspan="2">
				<!-- 
				<input type="text" name="textfield" id="textfield" /> 
				Zoeken
				-->
<a href="http://webshop.prijsgezocht.nl/docs/feeduitlegv1.pdf" target="_Blank">Feed Uitleg</a> - De feed kan later worden toegevoegd per webshop.
			</td>
			<td width="17%">&nbsp;</td>
			<td width="17%">Accounts 1 - <?=mysql_num_rows($result);?> van <?=mysql_num_rows($result);?></td>
		</tr>
		<tr bgcolor="#0099FF">
			<td style="color:#FFFFFF;">&nbsp;</td>
			<td style="color:#FFFFFF;">Webshop Naam</td>
			<td style="color:#FFFFFF;" width="17%">ShopID</td>
			<td style="color:#FFFFFF;" width="17%">Status</td>
			<td style="color:#FFFFFF;">Url</td>
			<td style="color:#FFFFFF;">&nbsp;</td>
		</tr>
		<?php
		$counter = 0;
		while($row = mysql_fetch_assoc($result))
		{
			$counter++;
			if($counter % 2 ==0)
			{
				?>
				<tr>
				<?php
			}
			else
			{
				?>
				<tr bgcolor="#DDE0FF">
				<?php
			}
			?>
				<td valign="top">
					<input type="checkbox" name="checkbox" id="checkbox" />
				</td>
				<td valign="top">
					<?php
					switch($row['Status'])
					{
						case '3':	 // active
						?>
						<img src="images/icons/oke.png" height="20px;" border="0" />
						<?=$row['Name'];?>
						<?php
						if($_SESSION['login']['ID'] < 5)
						{
						?>
							<input type="button" value=" Instellingen " onclick="javascript: selectWebshop('<?=$row['ID'];?>');" />
						<?php
						}
						break;
							
						case '4':	// deleted
							?>
							<img src="images/icons/error.png" height="20px;" border="0" />
							<?=$row['Name'];?>
							<?php
							break;
							
						default:	 // validate
							?>
							<a href="#" onClick="javascript: openPopup('/popup/validatewebshop.php?id=<?=$row['ID'];?>', 'Webshop valideren', 900, 500); return false;">
								<img src="images/icons/warning.png" height="20px;" border="0" />
								<?=$row['Name'];?>
							</a>
							<?php
							break;
					}
					?>
				</td>
				<td valign="top">
					<?=$row['ID'];?>
				</td>
				<td valign="top">
					<?php
					switch($row['Status'])
					{
						case '3':
							echo'Active';
							break;
							
						case '4':
							echo'Deleted <small>no longer visible for customers</small>';
							break;
							
						default:
							echo '<a href="#" onClick="javascript: openPopup(\'/popup/validatewebshop.php?id='.$row['ID'].'\', \'Webshop valideren\', 900, 500); return false;">';
							echo '<img src="images/icons/warning.png" height="20px;" border="0" />';
							echo 'Inactive <small>needs to be validated</small>';
							echo '</a>';
							break;
					}
					?>
				</td>
				<td valign="top">
					<?=$row['Website'];?>
				</td>
				<td valign="top">
					
				</td>
			</tr>
			<?php
		}
		?>
	</table>
	<br />
	<br />
	<script>
		function selectWebshop(id)
		{
			<?php
			if($_SESSION['login']['ID'] < 5)
			{
				?> 
				var url = 'factory/selectWebshop.php';
				$.post(
					url, 
					{
						webshopID: id
					}, 
					function(data){
						if(data == 'succes')
						{
							window.location = window.location;
						}
				});
				<?php
			}
			else
			{
				?>
				alert('Deze functionaliteit staat momenteel nog niet live.');
				<?php
			}
			?>
		}
	</script>
	<?php
}
else
{
	include_once "./home.php";
}